
import cn.dao.AccountDao;
import cn.domain.Account;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.springframework.transaction.support.ResourceHolderSynchronization;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class testMybits {

    @Test
    public void run2() throws Exception {
        InputStream in = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        SqlSession sqlSession = factory.openSession();
        AccountDao dao = sqlSession.getMapper(AccountDao.class);
        List<Account> all = dao.findAll();

        for (Account account : all) {
            System.out.println(account);
        }

        sqlSession.close();
        in.close();
    }
    @Test
    public void run3() throws Exception {
//        InputStream in = Resources.getResourceAsStream("SqlMapConfig.xml");
//        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
//        SqlSession sqlSession = factory.openSession();
//        AccountDao dao = sqlSession.getMapper(AccountDao.class);
//
//        Account account=new Account();
//        account.setName("王新宇");
//        account.setMoney(3000d);
//        dao.saveAccount(account);
//
//        sqlSession.commit();
//        sqlSession.close();
//        in.close();
//    }
}
}
